package com.skcc.cop.mrtaxi4driver.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.inputmethod.InputMethodManager;

public class Utils {
	
	public static String getFormattedDate() {
		Date now = new Date();
		SimpleDateFormat fomatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");

		return fomatter.format(now);
	}
	
	
	public static void hideSoftKeyboard(Activity activity) {
		if(activity==null) {
			return;
		}
		
		InputMethodManager inputMethodManager = (InputMethodManager)  activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
		if(activity.getCurrentFocus()!=null){
			Log.d("BaseActivity", "hideSoftKeyboard>> "+activity.getLocalClassName());
			inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
		}
	}
	
	/**
	 * @param r
	 */
	public static void makeLooperThread(Runnable r){
		Looper.prepare();
		Handler handler = new Handler(Looper.getMainLooper());
		handler.post(r);
		Looper.loop();
	}
	
	
	/**
	 * @param context context
	 * @return boolean
	 */
	public static boolean checkNetworkStatus(Context context)
	{
		ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		
		NetworkInfo mobile = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
		NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
		NetworkInfo lte_4g = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIMAX);
		
		boolean blte_4g = false;
		
		if (lte_4g != null)
		{
			blte_4g = lte_4g.isConnected();
		}
		
		if (mobile.isConnected() || wifi.isConnected() || blte_4g)
		{
			return true;
		}
		
		return false;
	}
	
}
